<template>
	<div>
		<div class="big_box">
			<el-breadcrumb separator="/">
				<el-breadcrumb-item>人员管理</el-breadcrumb-item>
				<el-breadcrumb-item>人员列表</el-breadcrumb-item>
			</el-breadcrumb>
			<el-divider></el-divider>
			<el-form class="demo-form-inline" :model="form" label-width="140px">
				<el-row :gutter="17" class="row-bg">
					<el-col :span="3">
						<el-input v-model="form.UserName" placeholder="员工姓名"></el-input>
					</el-col>
					<el-col :span="3">
						<el-input v-model="form.Card" placeholder="身份证号"></el-input>
					</el-col>
					<el-col :span="3">
						<el-input v-model="form.Phone" placeholder="手机号"></el-input>
					</el-col>
					<el-col :span="3">
						<el-input v-model="form.JobNumber" placeholder="工号"></el-input>
					</el-col>
					<el-col :span="2">
						<el-checkbox  v-model="form.Delete" label="已删除人员" border></el-checkbox>
					</el-col>
					<el-col :span="2">
						<el-button icon="el-icon-search" style="width:100%" @click="GettableDB()"></el-button>
					</el-col>
					<el-col :span="2">
						<el-button class="buttongroup" style="width:100%" type="success"
							icon="el-icon-circle-plus-outline" @click="ShowAddFinanceLoan">添加
						</el-button>
					</el-col>
					<el-col :span="2">
						<el-button class="buttongroup" style="width:100%" icon="el-icon-share"
							@click="handleDownload">导出
						</el-button>
					</el-col>

				</el-row>
			</el-form>
			<el-row style="padding-top:10px" :gutter="17">
				<el-col :span="2">
					<el-button class="buttongroup" style="width:100%" icon="el-icon-download"
						@click="DownloadHandler('user')">身份证下载</el-button>
				</el-col>
				<el-col :span="2">
					<el-button class="buttongroup" style="width:100%" icon="el-icon-download"
						@click="DownloadHandler('bank')">银行卡下载</el-button>
				</el-col>
				<el-col :span="2">
					<el-button type="danger" class="buttongroup" style="width:100%" icon="el-icon-delete"
						@click="DeleteUsers(null)">批量删除</el-button>
				</el-col>
			</el-row>
			<el-row style="padding-top: 10px">
				<el-col>
					<el-table :data="tableData" style="width: 100%" ref="multipleTable"
						@selection-change="selectionLineChangeHandle" border :row-style="{ height: '20px' }"
						:cell-style="{ padding: '5px 0 ' }">
						<el-table-column header-align="center" type="selection" width="50"
							align="center"></el-table-column>
						<el-table-column header-align="center" fixed type="index" label="序号" width="50" align="center"
							:index="_indexMethod"></el-table-column>
						<!-- <el-table-column header-align="center" fixed prop="DepartmentId" label="部门" align="center">
                        </el-table-column>   -->

						<el-table-column header-align="center" fixed prop="UserName" label="姓名" align="center">
						</el-table-column>

						<el-table-column header-align="center" prop="UserNumber" label="工号" align="center">
						</el-table-column>
						<el-table-column header-align="center" prop="Code" label="性别" align="center">
							<template slot-scope="scope">
								<label v-if="scope.row.Sex == 0">男</label>
								<label v-else>女</label>
							</template>
						</el-table-column>
						<el-table-column header-align="center" prop="RoleId" label="岗位" align="center"
							:show-overflow-tooltip="true">
							<template slot-scope="scope">
								{{ RoleNamesByids(scope.row.RoleId) }}
							</template>
						</el-table-column>
						<!-- <el-table-column header-align="center" prop="RoleDuty" label="岗位职责" align="center"
                                         :show-overflow-tooltip="true"></el-table-column>
                        <el-table-column header-align="center" prop="PostLevel" label="岗位等级"
                                         align="center"></el-table-column>
                        <el-table-column header-align="center" prop="Birth" label="出生日期" align="center" minWidth='150'>
                            <template slot-scope="scope">
                                {{_fmtDateGetStr(scope.row.Birth,"")}}
                            </template>
                        </el-table-column>
                        <el-table-column header-align="center" prop="Birth" label="年龄" align="center" width="110">
                            <template slot-scope="scope">
                                {{jsGetAge(scope.row.Birth)}}
                            </template>
                        </el-table-column> -->
						<el-table-column header-align="center" prop="Card" label="身份证号" align="center"
							width="180"></el-table-column>
						<el-table-column header-align="center" prop="Phone" label="联系电话" align="center"
							width="150"></el-table-column>
						<el-table-column header-align="center" prop="NowFamilyAddress" label="现居地" align="center"
							minWidth='330' :show-overflow-tooltip="true"></el-table-column>
						<el-table-column header-align="center" prop="FamilyAddress" label="户籍" align="center"
							minWidth='330' :show-overflow-tooltip="true"></el-table-column>
						<!-- <el-table-column header-align="center" prop="UserPosition" label="员工职务" align="center"
                                         width="110">
                            <template slot-scope="scope">
                                {{UserPositionByid(scope.row.UserPosition)}}
                            </template>
                        </el-table-column> -->
						<el-table-column header-align="center" prop="JobNumber" label="工种" align="center"
							width="110"></el-table-column>
						<el-table-column header-align="center" prop="InductionTime" label="入职时间" align="center"
							width="110">
							<template slot-scope="scope">
								{{ _fmtDateGetStr(scope.row.InductionTime, "") }}
							</template>
						</el-table-column>
						<!-- <el-table-column header-align="center" prop="Code" label="转正日期" align="center" width="110">
                            <template slot-scope="scope">
                                {{_fmtDateGetStr(scope.row.RegularDate,"暂未转正")}}
                            </template>
                        </el-table-column> -->
						<el-table-column header-align="center" prop="DepartureTime" label="离职日期" align="center"
							width="110">
							<template slot-scope="scope">
								{{ _fmtDateGetStr(scope.row.DepartureTime, "暂未离职") }}
							</template>
						</el-table-column>

						<el-table-column header-align="center" prop="BankCardNumber" label="银行卡号" align="center"
							minWidth='110' :show-overflow-tooltip="true"></el-table-column>
						<el-table-column header-align="center" prop="BankName" label="开户行" align="center" width="110"
							:show-overflow-tooltip="true"></el-table-column>
						<el-table-column header-align="center" prop="InternshipState" label="状态" align="center"
							width="110">
							<template slot-scope="scope">
								{{ getEmployState(scope.row.InternshipState) }}
							</template>
						</el-table-column>
						<!-- <el-table-column header-align="center" prop="PersonalProfile" label="个人简介" align="center"
                                         width="110" :show-overflow-tooltip="true"></el-table-column> -->
						<el-table-column header-align="center" prop="PersonalResume" label="身份证" align="center"
							width="210" :show-overflow-tooltip="true">
							<template slot-scope="scope">
								<el-button @click="PersonalResumeFc(scope.row)" type="text" size="small">
									{{ scope.row.PersonalResume }}点击查看
								</el-button>
								<el-button @click="DownUserId(scope.row)" type="text" size="small">
									{{ scope.row.PersonalResume }}下载
								</el-button>
								<el-button @click="DeleUserId(scope.row)" type="text" size="small">
									{{ scope.row.PersonalResume }}删除
								</el-button>
							</template>
						</el-table-column>
						<el-table-column header-align="center" prop="SkillsCertificate" label="银行卡" align="center"
							width="210" :show-overflow-tooltip="true">
							<template slot-scope="scope">
								<el-button @click="SkillsCertificateFc(scope.row,2)" type="text" size="small">
									{{ scope.row.SkillsCertificate }}点击查看
								</el-button>
								<el-button @click="DownBankCard(scope.row,2)" type="text" size="small">
									{{ scope.row.PersonalResume }}下载
								</el-button>
								<el-button @click="DeleBankCard(scope.row,2)" type="text" size="small">
									{{ scope.row.PersonalResume }}删除
								</el-button>
							</template>
						</el-table-column>
						<!-- <el-table-column header-align="center" prop="SkillsCertificate" label="银行卡2" align="center"
						    width="210" :show-overflow-tooltip="true">
						    <template slot-scope="scope">
						        <el-button @click="SkillsCertificateFc(scope.row,3)" type="text" size="small">
						            {{ scope.row.SkillsCertificate }}点击查看
						        </el-button>
						        <el-button @click="DownBankCard(scope.row,3)" type="text" size="small">
						            {{ scope.row.PersonalResume }}下载
						        </el-button>
						        <el-button @click="DeleBankCard(scope.row,3)" type="text" size="small">
						            {{ scope.row.PersonalResume }}删除
						        </el-button>
						    </template>
						</el-table-column> -->
						<!-- <el-table-column header-align="center" prop="Email" label="邮箱" align="center" minWidth='220'
                                         :show-overflow-tooltip="true"></el-table-column>
                        <el-table-column header-align="center" prop="Education" label="学历" align="center"
                                         width="110"></el-table-column>
                        <el-table-column header-align="center" prop="GraduateSchool" label="毕业学校" align="center"
                                         :show-overflow-tooltip="true"></el-table-column> -->
						<el-table-column header-align="center" prop="Remark" label="备注" align="center" width="110"
							:show-overflow-tooltip="true"></el-table-column>
						<el-table-column prop="address" header-align="center" align="center" label="操作" fixed="right"
							width="220px">
							<template slot-scope="scope">
								<el-button type="primary" class="BtnSize" size="mini" plain @click="edit(scope.row)">
									编辑
								</el-button>
								<el-button type="info" class="BtnSize" size="mini" plain @click="recoverDelUser(scope.row)">
									恢复
								</el-button>
								<el-button type="danger" class="BtnSize" size="mini" plain
									@click="DeleteUsers(scope.row)">
									删除
								</el-button>
							</template>
						</el-table-column>
					</el-table>
				</el-col>
				<el-col :span="24">
					<div class="block" style="float: right">
						<el-pagination @size-change="GettableDB" @current-change="GettableDB"
							:current-page.sync="pagination.currentPage" :page-sizes="pagination.pagesizes"
							:page-size.sync="pagination.pagesize" layout="total, sizes, prev, pager, next, jumper"
							:total.sync="pagination.total">
						</el-pagination>
					</div>
				</el-col>
			</el-row>

		</div>

		<el-dialog :visible.sync="AddUserShow" title="添加人员信息" top="10px" width="80%">
			<AddUserInfo :AllRoleDB="AllRoleDB" :AllDepartment="AllDepartment" :AllDutyMains="AllDutyMains">
			</AddUserInfo>
		</el-dialog>

		<el-dialog :visible.sync="UpUserShow" title="修改人员信息" top="10px" width="80%">
			<UpUserInfo :Upuser="Upuser" :AllRoleDB="AllRoleDB" :AllDepartment="AllDepartment"
				:AllDutyMains="AllDutyMains">
			</UpUserInfo>
		</el-dialog>

		<el-image-viewer v-if="showViewer" :on-close="() => { showViewer = false }" :url-list="imgArray" />


		<!--<el-dialog :visible.sync="PicShow" title="添加人员信息" width="70%">
        <div class="demo-image__preview">
            <el-image style="width: 100px; height: 100px"
                      :src="url"
                      :preview-src-list="srcList">
            </el-image>
        </div>
    </el-dialog>-->

		<el-dialog :visible.sync="flowChartData.show" v-if="flowChartData.show" title="人员架构图" width="100%" top="0">
			<flowChart :AllData="flowChartData.data"></flowChart>
		</el-dialog>


	</div>
</template>
<script>
	import * as publicjs from "/public/Scriput/Public"
	import AddUserInfo from "./AddUser";
	import UpUserInfo from "./UpUser";
	import FlowChart from "../FlowChart"
	import axios from 'axios';
	import * as mainjs from '../../main'
	export default {
		components: {
			AddUserInfo,
			UpUserInfo,
			FlowChart,
			axios,
			'el-image-viewer': () => import('element-ui/packages/image/src/image-viewer')
		},
		name: "UserInfo",
		data() {
			return {
				flowChartData: {
					show: false,
					data: {},
				},
				AddUserShow: false,
				UpUserShow: false,
				showViewer: false,
				PersonalResumeShow: false,
				Upuser: {},
				from: {},
				AllDepartment: [],
				AllRoleDB: [],
				AllState: [],
				//获取所有职务
				AllDutyMains: [],
				form: {},
				tableData: [],
				delidarray: [],

				//分页数据绑定
				pagination: {
					currentPage: 1,
					pagesizes: [15, 50, 100, ],
					pagesize: 15,
					total: 0
				},

				imgArray: [],
			};
		},
		created() {
			publicjs.http(this.$http, this.$message)
			this.AllDepartment = publicjs.GetAllDepartment(this.$http);
			this.AllRoleDB = publicjs.GetAllRole(this.$http);
			this.AllDutyMains = publicjs.GetAllDutyMains(this.$http);
		},
		methods: {
			_indexMethod(index) {
				return ((this.pagination.currentPage - 1) * this.pagination.pagesize) + index + 1
			},
			_GetFinanceLoanDetail() {},
			GetInternshipState() {
				let loadding = this.openLoading();
				this.$http.post("/UserInfo/GetInternshipState").then(res => {
					loadding.close();
					this.AllState = res.data.lis;
				});
			},
			DelArray() {},
			ShowAddFinanceLoan() {
				this.AddUserShow = true;
			},
			// 人员架构
			doFlowChart() {
				let data = {},
					flowChartData = {
						title: "人员架构图",
						titleBackground: "",
						titleColor: "",
						key: "big",
						subTitle: "",
						subTitleBackground: "",
						subTitleColor: "",
						children: []
					},
					dataType = {};
				let loadding = this.openLoading();
				this.$http.post("/UserInfo/GetUsersDetail", {
					limit: 100000,
					offset: 1,
					users: this.form.DepartmentId ? {
						DepartmentId: this.form.DepartmentId
					} : {},
				}).then(res => {
					loadding.close();
					data = res.data.data;
					/* for (let i = 0; i < data.length; i++) {
					    let item = data[i];
					    if (dataType[item.DepartmentId]) {
					        dataType[item.DepartmentId].children.push(item);
					    } else {
					        dataType[item.DepartmentId] = {
					            Department: this.GetDepartmentNameById(item.DepartmentId),
					            key: item.DepartmentId,
					            children: [item]
					        }
					    }
					} */
					for (let k in dataType) {
						let children = [];
						for (let i = 0; i < dataType[k].children.length; i++) {
							let item = dataType[k].children[i];
							children.push({
								title: "姓名",
								titleBackground: "",
								titleColor: "",
								key: dataType[k].key + "_" + item.Id + "_UserName",
								subTitle: item.UserName,
								subTitleBackground: "",
								subTitleColor: "",
								children: []
							});
							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "员工职务：",
								titleBackground: "",
								titleColor: "",
								subTitle: this.UserPositionByid(item.UserPosition),
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_UserPosition",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "性别：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.Sex ? "女" : "男",
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_Sex",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "岗位：",
								titleBackground: "",
								titleColor: "",
								subTitle: this.RoleNamesByids(item.RoleId),
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_RoleId",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "年龄：",
								titleBackground: "",
								titleColor: "",
								subTitle: this.jsGetAge(item.Birth),
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_Birth",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "联系电话：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.Phone,
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_Phone",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "现居地：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.NowFamilyAddress,
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_NowFamilyAddress",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "户籍：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.FamilyAddress,
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_FamilyAddress",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "在职时间（月）：",
								titleBackground: "",
								titleColor: "",
								subTitle: this._yearference(item),
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_DepartureTime",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "状态：",
								titleBackground: "",
								titleColor: "",
								subTitle: this.getEmployState(item.InternshipState),
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_InternshipState",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "学历：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.Education,
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_Education",
								children: []
							}, "children")

							children[children.length - 1].children = this.doChildrenData(children[children.length -
								1].children, {
								title: "毕业学校：",
								titleBackground: "",
								titleColor: "",
								subTitle: item.GraduateSchool,
								subTitleBackground: "",
								subTitleColor: "",
								key: dataType[k].key + "_" + item.Id + "_GraduateSchool",
								children: []
							}, "children")

						}
						flowChartData.children.push({
							title: dataType[k].Department,
							titleBackground: "",
							titleColor: "",
							key: "big",
							subTitle: "",
							subTitleBackground: "",
							subTitleColor: "",
							children: children
						})
					}
					this.flowChartData = {
						show: true,
						data: flowChartData,
					}
				});
			},
			handleDownload() {
				let _this = this;
				//获取选中文件
				let arrid = [];
				for (var i = 0; i < this.delidarray.length; i++) {
					arrid.push(this.delidarray[i].Id);
				}
				//批量删除

				if (arrid.length == 0) {
					this.$message.warning('您还未选择需要导出的人员!')
				} else {
					let loadding = this.openLoading();
					this.$http.post('UserInfo/GetUserInfoExcel', arrid).then(res => {
						loadding.close();
						this.arrid = []
						let linkHref = _this.$BasePath + res.data.path;
						console.log(linkHref);
						let isWindow = false;
						try {
							isWindow = command.getBtnState();
						} catch (error) {}
						if (isWindow) {
							command.downLoadResult(linkHref);
							return;
						}
						var link = document.createElement("a");
						link.href = linkHref;
						document.body.appendChild(link);
						link.click();
						document.body.removeChild(link);
					}).catch(() => {
						loadding.close();
						this.$message.error('服务器异常,请联系管理员!')
					})
				}

			},
			// 数据写入excel
			doChildrenData(data, children, key) {
				if (data.length) {
					data[0][key] = this.doChildrenData(data[0][key], children, key);
				} else {
					data = [children];
				}
				return data;
			},
			GettableDB() {
				let loadding = this.openLoading();
				this.$http.post("/UserInfo/GetUsersDetail", {
					users: this.form,
					offset: this.pagination.currentPage,
					limit: this.pagination.pagesize
				}).then(res => {
					loadding.close();
					this.tableData = res.data.data;
					this.pagination.total = res.data.count;
				});
			},
			//下载身份证
			DownUserId(obj) {
				this.$http.post("/UserInfo/DwonUserID", {
					user: obj
				}, {
					emulateJSON: true
				}).then(res => {
					if (!res.data.success) {
						this.$message.warning("文件不存在")
						return;
					}
					console.log(res.data)
					// Vue 组件中发送请求并下载PDF文件
					axios.get("/UserInfo/DwonUserFile?downPath=" + res.data.path, {
							responseType: 'blob'
						})
						.then(response => {
							const url = window.URL.createObjectURL(new Blob([response.data]));
							const link = document.createElement('a');
							link.href = url;
							link.setAttribute('download', res.data.filename);
							document.body.appendChild(link);
							link.click();
						})
						.catch(error => {
							console.error('Failed to download PDF file', error);
						});
				})
			},

			//下载银行卡
			DownBankCard(obj, type) {
				this.$http.post("/UserInfo/DwonBankCard", {
					user: obj,
					type: type
				}, {
					emulateJSON: true
				}).then(res => {
					if (!res.data.success) {
						this.$message.warning("文件不存在")
						return;
					}
					// Vue 组件中发送请求并下载PDF文件
					axios.get("/UserInfo/DwonUserFile?downPath=" + res.data.path, {
							responseType: 'blob'
						})
						.then(response => {
							const url = window.URL.createObjectURL(new Blob([response.data]));
							const link = document.createElement('a');
							link.href = url;
							link.setAttribute('download', res.data.filename);
							document.body.appendChild(link);
							link.click();
						})
						.catch(error => {
							console.error('Failed to download PDF file', error);
						});
				})
			},
			//删除身份证
			async DeleUserId(obj) {
				this.$confirm('确认刪除身份证吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'error'
				}).then(async () => {
					await this.$http.post('/UserInfo/DeleUserID', obj).then(x => {
						const {
							StatusCode
						} = x.data || 0
						if (StatusCode == 200) {
							this.$message.success("删除成功")
						} else {
							this.$message.error("删除失败");
						}
					});
				})
			},

			//删除银行卡
			async DeleBankCard(obj, type) {
				const {
					Id
				} = obj || 0
				this.$confirm('确认刪除银行卡吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'error'
				}).then(async () => {
					this.$http.post('/UserInfo/DeleBankCard', {
						Id,
						type
					}).then(x => {
						const {
							Success
						} = x.data || false
						if (Success) {
							this.$message.success("删除成功");
						} else {
							this.$message.error("删除失败");
						}
					}).catch(error => {
						console.error('删除失败系统错误:错误内容', error);
					});;
				})
			},

			_fmtDateGetStr(obj, str) {
				if (obj == null || obj == "") {
					return str;
				} else {
					return this.fmtDate(obj);
				}
			},
			_yearference(d) {
				if (d.DepartureTime == null || d.DepartureTime == "") {
					var now = new Date();
					var time = now.getFullYear() + "-" + ((now.getMonth() + 1) < 10 ? "0" : "") + (now.getMonth() + 1) +
						"-" + (now.getDate() < 10 ? "0" : "") + now.getDate();
					return this.monthdifference(this._fmtDateGetStr(d.InductionTime), time) + "月";
				} else {
					return this.monthdifference(this._fmtDateGetStr(d.InductionTime), this._fmtDateGetStr(d
						.DepartureTime)) + "月";
				}

			},

			monthdifference(date1, date2) { //sDate1和sDate2是2006-12-18格式
				// 拆分知年道月日
				date1 = date1.split('-');
				// 得到月数版权
				date1 = parseInt(date1[0]) * 12 + parseInt(date1[1]);
				// 拆分年月日
				date2 = date2.split('-');
				// 得到月数
				date2 = parseInt(date2[0]) * 12 + parseInt(date2[1]);
				return Math.abs(date1 - date2);
			},


			selectionLineChangeHandle(val) {
				this.delidarray = val;
			},

			//数据表格信息填写
			_deleCategory() {
				this.$confirm('你确定要删除吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'error'
				}).then(() => {
					let arrid = [];
					for (var i = 0; i < this.delidarray.length; i++) {
						arrid.push(this.delidarray[i].Id);
					}
					let loadding = this.openLoading();
					this.$http.post('/Finance/DeleteFinanceCategoryContent', arrid).then(x => {
						if (x.data.bit) {
							loadding.close();
							this.$message.success("删除成功")
						} else {
							loadding.close();
							this.$message.error("删除失败")
						}
					})

				})
			},
			//转换时间戳为年月日,20210108修复负数时间戳的转换问题
			fmtDate(obj) {
				//var result = "";
				//if (obj != null || obj != undefined) {
				//    var data = parseInt(new RegExp(/\d+/).exec(obj)[0]);
				//    if (obj.indexOf("-") > 0)
				//        data = -data;
				//    var date = new Date(data);
				//    var y = 1900 + date.getYear();
				//    var m = "0" + (date.getMonth() + 1);
				//    var d = "0" + date.getDate();
				//    if (y > 1920 && y < 2099)
				//        result = y + "-" + m.substring(m.length - 2, m.length) + "-" + d.substring(d.length - 2, d.length);
				//}

				return obj.split(' ')[0];
			},
			GetDepartmentNameById(obj) {
				return publicjs.GetDepartmentNameById(obj);
			},

			//权限名称
			RoleNamesByids(ids) {
				if (ids != "") {
					let rolenames = [];
					let idsstr = ids;
					let roleids = idsstr.split(',');
					let _this = this;
					roleids.forEach(function(item, index) {
						//item 就是当日按循环到的对象
						//index是循环的索引，从0开始
						let iid = parseInt(item);
						var role = _this.AllRoleDB.find((x) => x.Id == iid);
						if (role != null) {
							rolenames.push(role.RoleName);
						}
					})
					return rolenames.join(',');
				}
			},
			jsGetAge(obj) {
				return publicjs.jsGetAge(obj);
			},
			//填写完成
			edit(obj) {
				var objstr = JSON.parse(JSON.stringify(obj));
				this.Upuser = objstr;
				this.UpUserShow = true;
			},
			formal: function(data) {
				let _this = this;
				this.$confirm('确认设置为转正吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'success'
				}).then(async () => {
					if (data.InternshipState != 8) {
						data.InternshipState = 4; //转正
						data.InductionTime = _this.fmtDate(data.InductionTime);
						if (data.DepartureTime != null) {
							data.DepartureTime = _this.fmtDate(data.DepartureTime);
						}
						if (await _this.UpInternshipState(data) == 0) {
							_this.$message.warning("不能设置相同的状态");
							return;
						}
						_this.UpdataInternshipState(data, data.InternshipState);
						_this.GettableDB();
					} else {
						this.$message.warning("当前员工已离职!不能转正");
					}
				});
			},
			leave: function(data) {
				let _this = this;
				this.$confirm('确认设置为离职吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'error'
				}).then(async () => {
					data.InternshipState = 8; //状态设置为离职
					data.InductionTime = _this.fmtDate(data.InductionTime);
					if (data.DepartureTime != null) {
						data.DepartureTime = _this.fmtDate(data.DepartureTime);
					}
					if (await _this.UpInternshipState(data) == 0) {
						_this.$message.warning("不能设置相同的状态");
						return;
					}
					_this.UpdataInternshipState(data, data.InternshipState);
					_this.GettableDB();
				});
			},
			recover: function(data) {
				let _this = this;
				this.$confirm('确认设置为复职吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'info'
				}).then(async () => {
					data.InternshipState = 1; //状态设置为复职
					data.InductionTime = _this.fmtDate(data.InductionTime);
					if (data.DepartureTime != null) {
						data.DepartureTime = _this.fmtDate(data.DepartureTime);
					}
					if (await _this.UpInternshipState(data) == 0) {
						_this.$message.warning("不能设置相同的状态");
						return;
					}
					_this.UpdataInternshipState(data, data.InternshipState);
					_this.GettableDB();
				});
			},
			//将已删除的人员信息恢复
			recoverDelUser(data) {
				this.$confirm('你确定要恢复已删除员工吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'error'
				}).then(() => {
					let loadding = this.openLoading();
					this.$http.post('/UserInfo/RecoverDeleteUsersContent', data).then(x => {
						if (x.data) {
							loadding.close();
							this.$message.success("恢复成功")
						} else {
							loadding.close();
							this.$message.error("恢复失败")
						}
					})

				})
			},

			UpdataInternshipState: async function(employ, int) {
				let _this = this;
				let loadding = this.openLoading();
				await this.$http.post("/UserInfo/UpdataInternshipState", {
					users: employ,
					"id": int
				}).then(data => {
					if (data.data.flag) {
						loadding.close();
						_this.$message.success("修改成功");
					} else {
						loadding.close();
						_this.$message.warning("修改失败");
					}
				})
			},
			async UpInternshipState(employ) {
				let number = "";
				await this.$http.post("/UserInfo/UpInternshipState", {
					users: employ
				}).then(res => {
					number = res.data.bol;
				})
				return number;
			},
			getEmployState(obj) {
				var tate;
				if (obj == 1)
					tate = "试用期";
				else if (obj == 2)
					tate = "实习期";
				else if (obj == 4)
					tate = "正式期";
				else if (obj == 8)
					tate = "离职";
				else if (obj == 16)
					tate = "兼职";
				else
					tate = "未选择";
				return tate;
			},

			UserPositionByid(obj) {
				let mains = this.AllDutyMains.find(x => x.Id == obj);
				if (mains != null) {
					return (mains.DutyName);
				}
				return "";
			},
			async SkillsCertificateFc(obj, type) {
				this.imgArray = [];
				this.imgArray = await publicjs.GetAllFileByUrl(this.$http, "1," + obj.Id + "," + type);
				if (this.imgArray.length > 0) {
					this.showViewer = true;
				} else {
					this.$message.info("暂未上传图片");
				}
			},
			async PersonalResumeFc(obj) {
				this.imgArray = [];
				this.imgArray = await publicjs.GetAllFileByUrl(this.$http, "1," + obj.Id + ",1");
				/*  console.log(this.imgArray) */
				if (this.imgArray.length > 0) {
					this.showViewer = true;
				} else {
					this.$message.info("暂未上传图片");
				}
			},
			//人员删除
			DeleteUsers(row) {
				let ids = []
				if (row == null) {
					ids = this.delidarray.map(x => {
						return x.Id
					})
				} else {
					const {
						Id
					} = row || 0
					ids.push(Id)
				}
				if (ids.length == 0) {
					this.$message.warning('请选择你要删除的数据')
					return
				}
				this.$http.post('UserInfo/DeleteUsersContent', {
					ids
				}).then(res => {
					const {
						StatusCode,
						Data,
						Message
					} = res.data || 0
					if (StatusCode == 200) {
						this.GettableDB()
						this.$message.success('删除成功!')
					} else {
						this.$message.warning(Message)
					}
				})
			},
			//身份证/银行卡批量下载
			DownloadHandler(type) {
				if (this.delidarray.length == 0) {
					this.$message.warning('请选择你需要下载的人员列表')
					return
				}
				let ids = this.delidarray.map(x => {
					return x.Id
				})
				let url = ''
				if (type == 'user') url = 'UserInfo/DwonUserIDArr'
				else url = 'UserInfo/DwonBankCardArr'
				this.$http.post(url, {
					ids
				}).then(res => {
					const {
						StatusCode,
						Data,
						Message
					} = res.data || 0
					if (StatusCode == 200) {
						//文件下载
						publicjs.DownLoadFile({
							...Data
						})
					} else {
						this.$message.warning(Message)
					}
				})
			},
		},
		mounted: function() {
			this.GetInternshipState();
			this.GettableDB();
		},
	}
</script>

<style scoped></style>